<template>
	<view class="scroll-view_H">		
		<popup-layer ref="popupRef" :direction="'left'">
			<view style="position:absolute;margin-left: 2%;margin-top:15rpx;" @tap="chaxunclose()">
				<image :src="srcfanhui" class="item-icon-sys" mode=""></image>
			</view>
				<view class="box" style="border-bottom: 0px #bfbfbf solid;border-top: 1rpx #bfbfbf solid;padding-top: 5rpx;padding-bottom: 5rpx;">
					<view class="popupspan" style="width: 49.5%;text-align: center;border-right: 1px #bfbfbf solid;padding-left: 0rpx;font-size: 28rpx;" @tap="chaxunreset()">重置</view>
					<view class="popupinput" style="width: 49.5%;text-align: center;color: #6D8AF9;padding-right: 0rpx;" @tap="chaxunok()">确定</view>
				</view>
		</popup-layer>
		<view style="background-color: #FFFFFF;">
			<view class="box">
				<view class="popupspan">单据编号:</view>
				<view class="popupinput">
					<view class="inputff">{{inputdjbh}}</view>
				</view>
			</view>
			<view class="box">
				<view class="popupspan">制单日期:</view>
				<view class="popupinput">
					<view class="inputff">{{inputzdrq}}</view>
				</view>
			</view>
			<view class="box">
				<view class="popupspan">制单部门:</view>
				<view class="popupinput">
					<view data-id="zdbm" class="inputff">{{inputzdbm}}</view>
			</view>
			</view>
			<view class="box">
				<view class="popupspan">制单人:</view>
				<view class="popupinput">
					<view data-id="zdr" class="inputff">{{inputzdr}}</view>
			</view>
			</view>
			<view class="box">
				<view class="popupspan">处理方式:<image :src="scrbt" class="item-icon-bt" mode=""></image></view>
				<view class="popupinput">
					<!--<input type="text" v-model="inputglbm" placeholder="请输入管理部门" placeholder-class="inputff" @focus="focusshow($event)" data-Id="glbm"/>-->
				<view @tap="focusshow($event)" data-id="clfs" class="inputff">{{inputclfs}}</view>
				</view>
			</view>
			<view v-if="inputclfs!='请选择处理方式 >'">
				<view class="box">
					<view class="popupspan">{{inputzdbmspan}}:<image :src="scrbt" class="item-icon-bt" mode=""></image></view>
					<view class="popupinput">
						<view data-id="sybm" @tap="focusshow($event)" class="inputff">{{inputsybm}}</view>
				</view>
				</view>
				<view class="box">
					<view class="popupspan">{{inputzdrspan}}:<image :src="scrbt" class="item-icon-bt" mode=""></image></view>
					<view class="popupinput">
						<view data-id="syr" @tap="focusshow($event)" class="inputff">{{inputsyr}}</view>
				</view>
				</view>
				<view v-if="inputclfs=='借用出库'">
					<view class="box">
						<view class="popupspan">归还日期:<image :src="scrbt" class="item-icon-bt" mode=""></image></view>
							<view class="popupinput">
								<picker mode="date" :value="date" :start="startDate" :end="endDate"  @change="bindDateChange">
								     <view class="inputff">{{date}}</view>
								</picker>
							</view>
						</view>
					</view>
				</view>
	
			
		</view>
		
		<mescroll-body height="60%" ref="mescrollRef" @init="mescrollInit" @down="downCallback" :down="downOption" :up="upOption" @up="upCallback">
	<view class="" v-for="good in list" :key="good.id">
		<view class="Item">
			<view class="item-link item-content">
				<!--view class="item-inner" @tap="isanAsset($event)" :data-Id="good.Id"-->
				<view class="item-inner">
					<view v-if="good.资产状态=='库存'">
						<view class="item-text">
							<view  class="ispan" 
								style="background-color:#6D8AF9;width: 60rpx;color:#FFFFFF;padding: 0 10rpx;margin-right: 10rpx;border-radius:8rpx;">{{good.资产状态}}</view>
							<view class="ispan" style="width: 78%">资产编码：{{good.资产编码}}</view>
							<view class="ispan" style="width: 5%"><checkbox class="ispancheck" @tap="isanselectAsset($event)" :data-id="good.AssetId"></checkbox></view>
						</view>
					</view>
					<view v-else-if="good.资产状态=='在用'">
						<view class="item-text">
							<view  class="ispan" 
								style="background-color:#24C277;width: 60rpx;color:#FFFFFF;padding: 0 10rpx;margin-right: 10rpx;border-radius:8rpx;">{{good.资产状态}}</view>
							<view class="ispan" style="width: 78%">资产编码：{{good.资产编码}}</view>
							<view class="ispan" style="width: 5%">
								<!--view class="tki-tree-check">
									<view class="tki-tree-check-yes">
										<view class="tki-tree-check-yes-b"></view>
									</view>
									<view class="tki-tree-check-no"></view>
								</view-->
								<checkbox class="ispancheck" color="#6D8AF9" @tap="isanselectAsset($event)" :data-id="good.AssetId"></checkbox>
								</view>
						</view>
					</view>
					<view v-else-if="good.资产状态=='闲置'">
						<view class="item-text">
							<view  class="ispan" 
								style="background-color:#BEBEBE;width: 60rpx;color:#FFFFFF;padding: 0 10rpx;margin-right: 10rpx;border-radius:8rpx;">{{good.资产状态}}</view>
							<view class="ispan" style="width: 78%">资产编码：{{good.资产编码}}</view>
							<view class="ispan" style="width: 5%"><checkbox class="ispancheck" @tap="isanselectAsset($event)" :data-id="good.AssetId"></checkbox></view>
						</view>
					</view>
					<view v-else>
						<view class="item-text">
							<view  class="ispan" 
								style="background-color:#BEBEBE;width: 60rpx;color:#FFFFFF;padding: 0 10rpx;margin-right: 10rpx;border-radius:8rpx;">{{good.资产状态}}</view>
							<view class="ispan" style="width: 78%">资产编码：{{good.资产编码}}</view>
							<view class="ispan" style="width: 5%"><checkbox class="ispancheck" @tap="isanselectAsset($event)" :data-id="good.AssetId"></checkbox></view>
						</view>
					</view>
					
					
					<view v-if="inputclfs=='领用出库'">
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">资产类别:</view><view class="span">{{good.资产分类}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">领用部门:</view><view class="span">{{good.领用部门}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">领用人:</view><view class="span">{{good.领用人}}</view>
						</view>
					</view>
					<view v-else-if="inputclfs=='借用出库'">
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">资产类别:</view><view class="span">{{good.资产分类}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">借用部门:</view><view class="span">{{good.借用部门}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">借用人:</view><view class="span">{{good.借用人}}</view>
						</view>
					</view>
					<view v-else-if="inputclfs=='直接出库'">
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">资产类别:</view><view class="span">{{good.资产类别}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">使用部门:</view><view class="span">{{good.使用部门}}</view>
						</view>
						<view class="item-text" @tap="isanAsset($event)" :data-id="good.Id" :data-AssetId="good.AssetId" :data-DocumentId="good.DocumentId">
						<view class="ispan">使用人:</view><view class="span">{{good.使用人}}</view>
						</view>
					</view>
				</view>
				
			</view>
		</view>
	</view>
	</mescroll-body>
	
	<tab-bar class="fixs" ref='commentTabbat' :actives='active' :myactives='active'></tab-bar>
	
	<tki-tree ref="tkitree" :selectParent="selectParent" :multiple="multiple" :range="treelist" :foldAll="flod" rangeKey="Name" :title="title" :displayname="displayname"
	 @confirm="treeConfirm" @cancel="treeCancel"  :selectvalue="selectvalue" @KeyInput="treekeyinput"></tki-tree>
	 

	
	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import popupLayer from "@/components/popup-layer/popup-layer.vue";
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	import tkiTree from '@/components/tki-tree-asset/tki-tree.vue';
	import auiDialog from '@/components/aui-dialog/aui-dialog.vue';
	import tabBar from '@/components/tabbar/tabbar_add.vue';
	var self;
	function getDate(type) {
		const date = new Date();
	
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
	
		if (type === 'start') {
			year = year - 10;
		} else if (type === 'end') {
			year = year + 10;
		}
		if(type=="default"){
			return `请选择归还日期`;
		}
		month = month > 9 ? month : '0' + month;;
		day = day > 9 ? day : '0' + day;
	
		return `${year}-${month}-${day}`;
	}
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			MescrollBody
			,
			MescrollUni
			,
			popupLayer
			,
			tkiTree
			,
			tabBar
		},
		data() {
			return {
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {
					auto:true,
					native: false,
					beforeEndDownScroll:1000,
					textInOffset:"下拉刷新",
					textOutOffset:"释放刷新",
					textLoading:"加载中..."
				},upOption:{
					auto:true, // 不自动加载
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: ''
					},
					src: "../../static/images/totop.png",
					offset: 50,
					duration: 100,
					zIndex: 9990,
					right: 20,
					bottom: 120,
					safearea: false,
					width: 72,
					radius: "50%",
					left: null,
				},
				list:[],
				loginName: "",
				searchType:"",
				SumCount:"0",
				srcsys: "../../static/images/icon-sxuan.png",
				srcfanhui: "../../static/images/icon-fanhui-you.png",
				scrbt:"../../static/images/icon-bitian.png",
				inputgjz:"",
				inputdjbh:"",
				inputzcmc:"",
				inputzdrq:"",
				inputzdbm:"请选择制单部门 >",
				inputzdr:"请选择制单人 >",
				inputsybm:"请选择部门 >",
				inputsyr:"请选择人员 >",
				inputclfs:"请选择处理方式 >",
				inputdjzt:"请选择单据状态 >",
				inputzdbmspan:"使用部门",
				inputzdrspan:"使用人",
				inputzclbid:"",
				inputzdbmid:"",
				inputzdrid:"",
				inputclfsid:"",
				inputdjztid:"",	
				treelist: [],
				multiple: false,
				selectParent: true,
				displayname:"name",
				flod: false,
				Addflag:false,
				title:"选择资产类别",
				selectvalue:"",
				showTreeValue:false,
				ShowQueryValue:false,
				DocumentId:"",
				deleteids:"",
				DepartmentId:"",
				UserId:"",
				newtop:50,
				date: getDate('default'),
				startDate:getDate('start'),
				endDate:getDate('end'),
				auiDialog: {
					title: '',
					msg: '',
					btns: [{name: '确定'}],
					mask: true,
					maskTapClose: true,
					items: [],
					theme: 1,
				},
				
			}
		},
		computed: {
			tabHeightVal() {
				return this.newtop + 'px'
			}
		},
		onBackPress(options) {
			if(this.showTreeValue==true){
				this.showTreeValue=false;
				this.$refs.tkitree._hide();
				return true;
			}else{
				if(this.ShowQueryValue==true){
					this.ShowQueryValue=false;
					this.$refs.popupRef.close();
					return true;
				}else{
					return false;
				}
			}			
		}, 
		onNavigationBarButtonTap(val) {
			self=this;
			//return;
			if(val.index==0){//搜索
			
				uni.request({
					url:uni.getStorageSync("localurl")+'/Documents/App_Auditing',
					data: {
												DocumentId:self.DocumentId
					},
											method:"POST",
					success: (res) => {
						console.log(res);
						if (res.data.successed == true) {
							uni.navigateTo({
								url: '../asset/documentlist',
							});	
						}
					},
					fail: () => {
						//  请求失败,隐藏加载状态
						uni.navigateTo({
							url: '../asset/documentlist',
						});	
					}
				})
				}
			if(val.index==1){
				
				   }
		    },
		provide(){
			return {
				_mainFuncInit: this._mainFuncInit
			}
		},
		methods: {
			_mainFuncInit(){
				self=this;
				this.active = uni.getStorageSync('setStatusIndexFunc') || 0;
				console.log(this.active);
				if(this.active==0){
					if(self.DocumentId==""){
						if(self.inputclfsid!=""){
						var _newdate=new Date();
						var newdata={
							BillHandleTypeId: self.inputclfsid,
							_r: "661aea12-cb28-4c92-9a78-66c519a630c9",
							CreatedByUserId: self.UserId,
							CreatorDepartmentId: self.DepartmentId
							
						};
					uni.request({
						url:uni.getStorageSync("localurl")+'/Documents/Save_Document_Model',
						data: newdata,
						method:"POST",
						success: (res) => {
							console.log(res);
							if (res.data.successed == true) {
								self.inputdjbh=res.data.Code;
								self.DocumentId=res.data.Id;
								if(self.inputsybmid=="" ||  self.inputsybmid==null){
									uni.showToast({
										icon: 'none',
										title: '请选择'+self.inputzdbmspan,
										duration: 2000
									});
									return;
								}
								if(self.inputsyrid=="" ||  self.inputsyrid==null){
									uni.showToast({
										icon: 'none',
										title: '请选择'+self.inputzdrspan,
										duration: 2000
									});
									return;
								}
								if(self.inputclfs=="借用出库"){
								if(self.date=="请选择归还日期"){
									uni.showToast({
										icon: 'none',
										title: '请选择归还日期',
										duration: 2000
									});
									return;
								}
								}
								uni.navigateTo({
									url: "../asset/assetlist_select?DocumentId="+self.DocumentId+"&DocumentCode="+self.inputdjbh+"&MoveinDeaprtmentId="+self.inputsybmid+"&MoveinMenId="+self.inputsyrid+"&RefDate="+self.date,
								});	
								//this.focusshowasset();
							}
						},
						fail: () => {
							//  请求失败,隐藏加载状态
							this.mescroll.endErr()
						}
					})
					}else{
						uni.showToast({
							icon: 'none',
							title: '请选择处理方式',
							duration: 2000
						});
					}
					}else{
						if(self.inputsybmid=="" ||  self.inputsybmid==null){
							uni.showToast({
								icon: 'none',
								title: '请选择'+self.inputzdbmspan,
								duration: 2000
							});
							return;
						}
						if(self.inputsyrid=="" ||  self.inputsyrid==null){
							uni.showToast({
								icon: 'none',
								title: '请选择'+self.inputzdrspan,
								duration: 2000
							});
							return;
						}
						if(self.inputclfs=="借用出库"){
						if(self.date=="请选择归还日期"){
							uni.showToast({
								icon: 'none',
								title: '请选择归还日期',
								duration: 2000
							});
							return;
						}
						}
						uni.navigateTo({
							url: "../asset/assetlist_select?DocumentId="+self.DocumentId+"&DocumentCode="+self.inputdjbh+"&MoveinDeaprtmentId="+self.inputsybmid+"&MoveinMenId="+self.inputsyrid+"&RefDate="+self.date,
						});	
						//this.focusshowasset();
					}
				
				}else if(this.active==1){
					// 只允许通过相机扫码
					console.log(self.DocumentId);
					if(self.DocumentId==""){
						if(self.inputclfsid!=""){
						var _newdate=new Date();
						var newdata={
							BillHandleTypeId: self.inputclfsid,
							_r: "661aea12-cb28-4c92-9a78-66c519a630c9",
							CreatedByUserId: self.UserId,
							CreatorDepartmentId: self.DepartmentId,
							CreatedOnDate:"2021-03-19"
						};
					uni.request({
						url:uni.getStorageSync("localurl")+'/Documents/Save_Document_Model',
						data: newdata,
						method:"POST",
						success: (res) => {
							console.log(res);
							if (res.data.successed == true) {
								self.inputdjbh=res.data.Code;
								self.DocumentId=res.data.Id;
								if(self.inputzdbmid==""){
									uni.showToast({
										icon: 'none',
										title: '请选择'+self.inputzdbmspan,
										duration: 2000
									});
									return;
								}
								if(self.inputzdrid==""){
									uni.showToast({
										icon: 'none',
										title: '请选择'+self.inputzdrspan,
										duration: 2000
									});
									return;
								}
								uni.setStorageSync('DocumentId',self.DocumentId);
								uni.setStorageSync('scanmytype', "edit");
								uni.setStorageSync('scaneditDocumentId', self.DocumentId);
								uni.navigateTo({
									url: '../home/scan-stock',
								});
								return;
								var url=window.location.href.split("#")[0];//该paramUrl 为你使用微信sdk-js相关接口的页面地址 该地址需要配置到应用后台的可信域名下，你也可以理解为项目访问的地址;
								console.log(url);
								uni.request({
									url:uni.getStorageSync("localurl")+'/Documents/WX_GetToken', //仅为示例，并非真实接口地址。
									data: {
										url: url
									},
									method: "POST",
									success: res2 => {
										if (res2.data.successed == true) {
											console.log(res2);
											console.log("调用成功");
														jWeixin.config({
														    beta: true,// 必须这么写，否则wx.invoke调用形式的jsapi会有问题
														    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
														    appId: res2.data.model.appId, // 必填，企业微信的corpID
														    timestamp: res2.data.model.timpstamp, // 必填，生成签名的时间戳
														    nonceStr: res2.data.model.noncestr, // 必填，生成签名的随机串
														    signature: res2.data.model.signature,// 必填，签名，见 附录-JS-SDK使用权限签名算法
														    jsApiList: ["scanQRCode", "openLocation"] // 必填，需要使用的JS接口列表，凡是要调用的接口都需要传进来
														});
														 jWeixin.ready(function() {
														        jWeixin.checkJsApi({
														            jsApiList: ["invoke", "scanQRCode"], // 需要检测的JS接口列表，所有JS接口列表见附录2,
														            success: res => {
																		console.log(res);
												
														                
														            }
														        });
														        jWeixin.invoke("enterpriseVerify", {}, res => {
														            
														        });
														
														jWeixin.scanQRCode({
														
																desc: 'scanQRCode desc',
																needResult: 1, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
																scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
																success: function(res) {
																	const resmodel=JSON.parse(res.resultStr); 
																	if(resmodel.唯一标识!=undefined){
																		var added =[];
																		added.push(resmodel.唯一标识);
																		uni.request({
																			url:uni.getStorageSync("localurl")+'/Documents/Asset_Change_Add_Detail_Save',
																			data: {
																				_Added: added,
																				_r: "dde7a3ef-2a1a-4494-880f-7c4f56dd0f9e",
																				_Removed: [],
																				DocumentId:self.DocumentId
																			},
																									method:"POST",
																			success: (res) => {
																				console.log(res);
																				self.ShowQueryValue=false;
																				self.$refs.popupRef.close();
																				self.downCallback();
																				
																			},
																			fail: () => {
																				//  请求失败,隐藏加载状态
																				
																			}
																		});
																	}else{
																		uni.showToast({
																		icon: 'none',
																		title: '无法识别二维码'
																		});	
																	}														                
																},
																	error: function(res) {
																		if (res.errMsg.indexOf('function_not_exist') > 0) {
																			alert('版本过低请升级')
																		}
																	}
														
																});
														    });
											//this.model = res.data.model;
										} else {
											console.log(res2);
											uni.showToast({
												icon: 'none',
												title: res2.data.responseState,
												duration: 1500,
											});
										}
										uni.hideNavigationBarLoading();
									},
									fail: () => {
								
										uni.showToast({
											icon: 'none',
											title: '网络异常,请稍后重试'
										});
									}
								});
									
							}
						},
						fail: () => {
							//  请求失败,隐藏加载状态
							this.mescroll.endErr()
						}
					})
					}else{
						uni.showToast({
							icon: 'none',
							title: '请选择处理方式',
							duration: 2000
						});
					}
					}else{
						uni.setStorageSync('DocumentId',self.DocumentId);
						uni.setStorageSync('scanmytype', "edit");
						uni.setStorageSync('scaneditDocumentId', self.DocumentId);
						uni.navigateTo({
							url: '../home/scan-stock',
						});	
					}
					
					
				}else if(this.active==3){
					if(self.deleteids==""){
						uni.showToast({
							icon: 'none',
							title: '请选择删除资产',
							duration: 2000
						});
					}else{
						const _newRemoved =self.deleteids.split(",");
						const _Removed=[];
						for(var i=0;i<_newRemoved.length;i++){
							_Removed.push(_newRemoved[i]);
						}
						self.deleteids="";
						console.log(_Removed);
						uni.request({
							url:uni.getStorageSync("localurl")+'/Documents/Asset_Change_Add_Detail_Save',
							data: {
								_Added: [],
								_r: "dde7a3ef-2a1a-4494-880f-7c4f56dd0f9e",
								_Removed: _Removed,
														DocumentId:self.DocumentId
							},
													method:"POST",
							success: (res) => {
								if (res.data.successed == true) {
									this.downCallback();
								}
							},
							fail: () => {
								//  请求失败,隐藏加载状态
								this.mescroll.endErr()
							}
						})
					}
				}
			},
			_initData(){
				this._mainFuncInit();
			},
			/*下拉刷新的回调, 有三种处理方式:*/
			downCallback() {
				this.list=[];
				this.mescroll.resetUpScroll();
			
			},
			/*下拉加载的回调*/
			upCallback(page) {
				self = this;
				if(self.DocumentId!=""){
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				uni.request({												
					url:uni.getStorageSync("localurl")+'/Documents/Get_Document_Detail_List',
					data: {
						pageSize: pageSize,
						_r: "dde7a3ef-2a1a-4494-880f-7c4f56dd0f9e",
						pageIndex: pageNum-1,
						DocumentId:self.DocumentId
						
					},
					success: (res) => {
						
						if (res.data.successed == true) {
							var mydata = [];
							self.SumCount=res.data.total;
							var newrows = JSON.parse(res.data.rows);
							for (var i = 0; i < newrows.length; i++) {
								var valueRows = newrows[i].toString().split(',');
								var datarow = {};
								for (var j = 0; j < res.data.columns.length; j++) {
									datarow[res.data.columns[j].字段名] = valueRows[j];
								}
								mydata.push(datarow);
								
							}
						console.log(mydata);
							if(mydata.length>0){
								self.inputsybmid=mydata[0]["UsingDepartmentId"];
								self.inputsyrid=mydata[0]["UsingMenId"];
								if(mydata[0]["借用部门"]!=undefined){
								self.inputsybm=mydata[0]["借用部门"];
								self.inputsyr=mydata[0]["借用人"];
								
								self.date=mydata[0]["计划归还日期"];
								}else if(mydata[0]["领用部门"]!=undefined){
									self.inputsybm=mydata[0]["领用部门"];
									self.inputsyr=mydata[0].领用人;
									}
									else if(mydata[0]["使用部门"]!=undefined){
										self.inputsybm=mydata[0].使用部门;
										self.inputsyr=mydata[0].使用人;
										}
							}
							
							//this.productList = mydata;
							// 接口返回的当前页数据列表 (数组)
							let curPageData = mydata; 
							// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
							let curPageLen = mydata.length; 
							// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
							let totalPage = res.data.total/page.size; 
							// 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
							let totalSize = res.data.total; 
							// 接口返回的是否有下一页 (true/false)
							let hasNext =false; 
							 //设置列表数据
							 //console.log(curPageData);
							 if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
							 this.list = this.list.concat(curPageData); //追加新数据
							 
							 // 请求成功,隐藏加载状态
							 //方法一(推荐): 后台接口有返回列表的总页数 totalPage
							 this.mescroll.endByPage(curPageLen, totalPage); 
							 
							 // 如果数据较复杂,可等到渲染完成之后再隐藏下拉加载状态: 如
							 // 建议使用setTimeout,因为this.$nextTick某些情况某些机型不触发
							 setTimeout(()=>{
							 	this.mescroll.endSuccess(curPageLen)
							 },20)
						
														 
							}
						},
						fail: () => {
								//  请求失败,隐藏加载状态
								this.mescroll.endErr()
							}
						})
				// 此处仍可以继续写其他接口请求...
				// 调用其他方法...	
												}else{
													this.mescroll.endSuccess(1)
													}
			},
			queryasset(){
				uni.request({
					url:uni.getStorageSync("localurl")+'/Documents/Query_Document_List',
					data: {
						pageSize: 5,
						_r: "dde7a3ef-2a1a-4494-880f-7c4f56dd0f9e",
						pageIndex: 0,
					},
					success: (res) => {
						console.log(res);
						if (res.data.successed == true) {
							//sumCount
							//self.list=res.data;
						}
					},
					fail: () => {
						//  请求失败,隐藏加载状态
						this.mescroll.endErr()
					}
				})
			},
			isanAsset(e){
				
				uni.navigateTo({
					url: '../asset/asset?Id=' + e.currentTarget.dataset.assetid+'&documentDetailId='+e.currentTarget.dataset.id+"&documentId="+e.currentTarget.dataset.documentId,
				});
				
			},
			isanselectAsset(e){
				self=this;
				console.log("AAAAAAAA"+self.deleteids);
				if(self.deleteids.indexOf(e.currentTarget.dataset.id)>-1){
					if(self.deleteids==e.currentTarget.dataset.id){
						self.deleteids="";
					}else{
						self.deleteids=self.deleteids.replace(e.currentTarget.dataset.id+",","");
					}
					}else{
						if(self.deleteids==""){
							self.deleteids=e.currentTarget.dataset.id;
						}else{
							self.deleteids=self.deleteids+","+e.currentTarget.dataset.id;
						}
					
						}
				
			},
			sxchaxun(){
				this.ShowQueryValue=true;
				 this.$refs.popupRef.show();
			},
			chaxunclose(){
				this.ShowQueryValue=false;
				this.$refs.popupRef.close();
			},
			chaxunreset(){
				this.inputzcbm="";
				this.inputzcmc="";
				this.inputzdbm="请选择制单部门";
				this.inputzdr="请选择制单人";
				this.inputclfs="请选择处理方式";
				this.inputdjzt="请选择单据状态";
				this.inputzdbmid="";
				this.inputzdrid="";
				this.inputclfsid="";
				this.inputdjztid="";
				this.ShowQueryValue=false;
				this.$refs.popupRef.close();
				this.downCallback();
			},
				chaxunok(){
					this.ShowQueryValue=false;
					this.$refs.popupRef.close();
					this.downCallback();
				},
				focusshow(e){
				
					this.selectvalue=e.currentTarget.dataset.id;
					this.treelist=[];
					this.$refs.tkitree.oldtreeList="";
					this.$refs.tkitree.servalue="";
					console.log(e.currentTarget.dataset.id);
					if(e.currentTarget.dataset.id=="sybm"){
						this.showTree();
						this.title="请选择部门";
						this.multiple=false;
						this.displayname="name";
						this.loadDepartment();
					}else if(e.currentTarget.dataset.id=="syr"){
						
						if(this.inputsybmid=="" || this.inputsybmid==null){
							uni.showToast({
								icon: 'none',
								title: '请选择部门'
							});
							return;
						}else{
							this.showTree();
							this.title="请选择人员";
							this.multiple=false;
							this.displayname="name";
							this.loadglbmProfile();
						}
					}else if(e.currentTarget.dataset.id=="clfs"){
						if(this.DocumentId==""){
						this.showTree();
						this.title="请选择处理方式";
						this.multiple=false;
						this.displayname="name";
						this.loadRouteHandler();
						}
					}else if(e.currentTarget.dataset.id=="djzt"){
						this.showTree();
						this.title="请选择单据状态";
						this.multiple=false;
						this.displayname="name";
						this.loadDictionary();
					}
					
					
				},
				focusshowasset(e){
					this.selectvalue="selzc";
					this.treelist=[];
					this.$refs.tkitree.oldtreeList="";
					this.$refs.tkitree.servalue="";
					
					this.showTree();
					this.title="请选择资产";
					this.multiple=true;
					this.displayname="name";
					this.loadAssets();
					
					
				},
				// 确定回调事件
				treeConfirm(e) {
					self=this;
					this.showTreeValue=false;
					if(this.selectvalue=="zclb"){
						this.inputzclb=e[0].Name;
						this.inputzclbid=e[0].Id;
					}else if(this.selectvalue=="sybm"){
						this.inputsybm=e[0].Name;
						this.inputsybmid=e[0].Id;
					}else if(this.selectvalue=="syr"){
						this.inputsyr=e[0].Name;
						this.inputsyrid=e[0].Id;
					}else if(this.selectvalue=="clfs"){
						this.inputclfs=e[0].Name;
						this.inputclfsid=e[0].Id;
						if(this.inputclfs=="直接出库"){
							self.inputzdbmspan="使用部门";
							 self.inputzdrspan="使用人";
							}
						if(this.inputclfs=="借用出库"){
													self.inputzdbmspan="借用部门";
													 self.inputzdrspan="借用人";
													}
						if(this.inputclfs=="领用出库"){
													self.inputzdbmspan="领用部门";
													 self.inputzdrspan="领用人";
													}
						
					}else if(this.selectvalue=="djzt"){
						this.inputdjzt=e[0].Name;
						this.inputdjztid=e[0].Id;
					}
					else if(this.selectvalue=="selzc"){
							 var added =[];
							for(var i=0;i<e.length;i++){
								added.push(e[i].Id);
							}
						   
						   uni.request({
						   	url:uni.getStorageSync("localurl")+'/Documents/Asset_Change_Add_Detail_Save',
						   	data: {
						   		_Added: added,
						   		_r: "dde7a3ef-2a1a-4494-880f-7c4f56dd0f9e",
						   		_Removed: [],
								DocumentId:self.DocumentId,
						   	},
							method:"POST",
						   	success: (res) => {
						   		console.log(res);
						   		if (res.data.successed == true) {
						   			this.downCallback();
						   		}
						   	},
						   	fail: () => {
						   		//  请求失败,隐藏加载状态
						   		this.mescroll.endErr()
						   	}
						   })
					}
					
				},
				// 取消回调事件
				treeCancel(e) {
					this.showTreeValue=false;
					console.log(e)
				},	
				treekeyinput(value){
					let bmid="";
					if(this.selectvalue=="zrr"){
						bmid=this.inputglbmid;
					}
					if(this.selectvalue=="syr"){
						bmid=this.inputsybmid;
					}
					
					this.request_tool({
						url:'/console/app/v1/operator/pageData',
						type:'POST',
						data:{"orgId":bmid,"userName":value,"current":0,"pageSize":100}
					}).then(res => {
							//console.error(res);
							if(res!=undefined){
							if (res.data.code == 2000) {
								//console.log(res.data.data);
								//self.treelist= res.data.data;
								let newtreelist=[];
								for(var i=0;i<res.data.data.records.length;i++){
									let resitem= res.data.data.records[i];
									let treeitem={
										id:resitem.id,
										label:resitem.userName,
										isEnabled:resitem.isEnabled,
										checked:false,
										children:[],
									};
									newtreelist.push(treeitem);
								}
								self.treelist=newtreelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 2000);
								this.$refs.tkitree.oldtreeList="";
								this.$refs.tkitree.servalue=value;
								this.showTree();
								//this.model = res.data.model;
							}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
							}
							}).catch(err => {
					  console.error(err);
					  
					});
					
					//this.treelist=newtreeList;
				},
				// 显示树形选择器
				showTree() {
					this.showTreeValue=true;
					this.$refs.tkitree._show();
				},

				loadAssetType(){
					self=this;
					uni.showNavigationBarLoading();
					uni.request({
						url:uni.getStorageSync("localurl")+'/Common/TreeSelector', //仅为示例，并非真实接口地址。
						data: {
							_Type: "AmsAssetTypes",
						},
						success: res2 => {
							
							if (res2.data.successed == true) {
								//console.log(res2.data.data);
								var _typelist=[];
								for(var i=0;i<res2.data.data.length;i++){
									var model=res2.data.data[i];								
									var child=[];
									var _type={};
									_type.Id=model.Id;
									_type.Name=model.Name;
									for(var j=0;j<model.children.length;j++){
										var model1=model.children[j];
										var child1=[];
										var _type1={};
										_type1.Id=model1.Id;
										_type1.Name=model1.Name;
										for(var s=0;s<model1.children.length;s++){
											var model2=model1.children[s];
											var child2=[];
											var _type2={};
											_type2.Id=model2.Id;
											_type2.Name=model2.Name;
											
											_type2.children=child2;
											child1.push(_type2);									
										}
										_type1.children=child1;
										child.push(_type1);
									}
									
									_type.children=child;
									_typelist.push(_type);
								}
								self.treelist= _typelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 1000);
								//this.model = res.data.model;
							}
						},
						fail: () => {
					
							uni.showToast({
								icon: 'none',
								title: '网络异常,请稍后重试'
							});
						}
					});
					
				},
				loadDepartment(){
					self=this;
					uni.showNavigationBarLoading();
					uni.request({
						url:uni.getStorageSync("localurl")+'/Common/TreeSelector', //仅为示例，并非真实接口地址。
						data: {
							_Type: "AmsDepartments",
						},
						success: res2 => {
							if (res2.data.successed == true) {
								self.treelist= res2.data.data;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 2000);
								
								//this.model = res.data.model;
							}
						},
						fail: () => {
							uni.hideNavigationBarLoading();
							uni.showToast({
								icon: 'none',
								title: '网络异常,请稍后重试'
							});
						}
					});
				},
				loadglbmProfile(){
					self=this;
								
					uni.showNavigationBarLoading();
				
					self.request_tool({
						url:'/console/app/v1/operator/pageData',
						type:'POST',
						data:{"orgId":self.inputglbmid,"current":0,"pageSize":100}
					}).then(res => {
							console.error(res);
							if(res!=undefined){
							if (res.data.code == 2000) {
								console.log(res.data.data);
								//self.treelist= res.data.data;
								let newtreelist=[];
								for(var i=0;i<res.data.data.records.length;i++){
									let resitem= res.data.data.records[i];
									let treeitem={
										id:resitem.id,
										label:resitem.userName,
										isEnabled:resitem.isEnabled,
										checked:false,
										children:[],
									};
									newtreelist.push(treeitem);
								}
								self.treelist=newtreelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 2000);
								this.$refs.tkitree.oldtreeList="";
								this.$refs.tkitree.servalue="";
								this.showTree();
								//this.model = res.data.model;
							}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
							}
							}).catch(err => {
					  console.error(err);
					  
					});
					
					
				},
				loadsybmProfile(){
					self=this;
					uni.showNavigationBarLoading();
					self.request_tool({
						url:'/console/app/v1/operator/pageData',
						type:'POST',
						data:{"orgId":self.inputsybmid,"current":0,"pageSize":100}
					}).then(res => {
							console.error(res);
							if(res!=undefined){
							if (res.data.code == 2000) {
								console.log(res.data.data);
								//self.treelist= res.data.data;
								let newtreelist=[];
								for(var i=0;i<res.data.data.records.length;i++){
									let resitem= res.data.data.records[i];
									let treeitem={
										id:resitem.id,
										label:resitem.userName,
										isEnabled:resitem.isEnabled,
										checked:false,
										children:[],
									};
									newtreelist.push(treeitem);
								}
								self.treelist=newtreelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 2000);
								this.$refs.tkitree.oldtreeList="";
								this.$refs.tkitree.servalue="";
								this.showTree();
								//this.model = res.data.model;
							}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
							}
							}).catch(err => {
					  console.error(err);
					  
					});
					
				},
				loadRouteHandler(){
					self=this;
					
					uni.showNavigationBarLoading();
					uni.request({
						url:uni.getStorageSync("localurl")+'/Common/TreeSelector', //仅为示例，并非真实接口地址。
						data: {
							_Type: "AmsRouteHandlers",
							_Root:"793212f5-f44e-4bfa-b46d-0f3bd67b03a9"
						},
						success: res2 => {
							
							if (res2.data.successed == true) {
								//console.log(res2.data.data);
								var _typelist=[];
								for(var i=0;i<res2.data.data.length;i++){
									var model=res2.data.data[i];								
									var child=[];
									var _type={};
									_type.Id=model.Id;
									_type.Name=model.Name;
									for(var j=0;j<model.children.length;j++){
										var model1=model.children[j];
										var child1=[];
										var _type1={};
										_type1.Id=model1.Id;
										_type1.Name=model1.Name;
										for(var s=0;s<model1.children.length;s++){
											var model2=model1.children[s];
											var child2=[];
											var _type2={};
											_type2.Id=model2.Id;
											_type2.Name=model2.Name;
											
											_type2.children=child2;
											child1.push(_type2);									
										}
										_type1.children=child1;
										child.push(_type1);
									}
									
									_type.children=child;
									_typelist.push(_type);
								}
								self.treelist= _typelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 1000);
								//this.model = res.data.model;
							}
						},
						fail: () => {
					
							uni.showToast({
								icon: 'none',
								title: '网络异常,请稍后重试'
							});
						}
					});
					
				},loadDictionary(){
					self=this;
					
					uni.showNavigationBarLoading();
					uni.request({
						url:uni.getStorageSync("localurl")+'/Common/TreeSelector', //仅为示例，并非真实接口地址。
						data: {
							_Type: "AmsDictionarys",
							_Root:"00000000-0000-0000-0000-000000000001"
						},
						success: res2 => {
							
							if (res2.data.successed == true) {
								//console.log(res2.data.data);
								var _typelist=[];
								for(var i=0;i<res2.data.data.length;i++){
									var model=res2.data.data[i];								
									var child=[];
									var _type={};
									_type.Id=model.Id;
									_type.Name=model.Name;
									for(var j=0;j<model.children.length;j++){
										var model1=model.children[j];
										var child1=[];
										var _type1={};
										_type1.Id=model1.Id;
										_type1.Name=model1.Name;
										for(var s=0;s<model1.children.length;s++){
											var model2=model1.children[s];
											var child2=[];
											var _type2={};
											_type2.Id=model2.Id;
											_type2.Name=model2.Name;
											
											_type2.children=child2;
											child1.push(_type2);									
										}
										_type1.children=child1;
										child.push(_type1);
									}
									
									_type.children=child;
									_typelist.push(_type);
								}
								self.treelist= _typelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 1000);
								//this.model = res.data.model;
							}
						},
						fail: () => {
					
							uni.showToast({
								icon: 'none',
								title: '网络异常,请稍后重试'
							});
						}
					});
					
				},
				loadAssets(){
					self=this;
					uni.showNavigationBarLoading();
					uni.request({
						url:uni.getStorageSync("localurl")+'/Common/TreeSelector', //仅为示例，并非真实接口地址。
						data: {
							_Type: "AmsAssets",
							pageSize:500,
							AssetStatusId:"E7AABCEC-AAF2-4B40-B7D5-8ECA5D9D1314"
							
						},
						success: res2 => {
							console.log(res2);
							if (res2.data.successed == true) {
								var mydata = [];
								var newrows = JSON.parse(res2.data.rows);
								for (var i = 0; i < newrows.length; i++) {
									var valueRows = newrows[i].toString().split(',');
									var datarow = {};
									for (var j = 0; j < res2.data.columns.length; j++) {
										//alert(_data.columns[j].字段名)
										datarow[res2.data.columns[j].字段名] = valueRows[j];
									}
									datarow.children=[];
									datarow.anyChildChecked=null;
									datarow.checked=null;
									datarow.state=null;
									mydata.push(datarow);
									
								}
								console.log(mydata);
								
								self.treelist=mydata;
								uni.hideNavigationBarLoading();
								//this.model = res.data.model;
							}
						},
						fail: () => {
							uni.hideNavigationBarLoading();
							uni.showToast({
								icon: 'none',
								title: '网络异常,请稍后重试'
							});
						}
					});
				},
				bindDateChange: function(e) {
					this.date = e.detail.value;
				},
		},
		onLoad(options) {
			//首先将实例指针保存到全局变量 self 方便在异步请求中访问实例本身
			
			self=this;
			//底部导航开始
			let temp = uni.getStorageSync('setStatusIndexFunc') || 0
			uni.setStorageSync('setStatusIndexFunc', temp)
			this.active = temp
			this.$nextTick(()=>{
				this.$refs.commentTabbat.getSetting(temp)
				this._initData();
			})
			uni.request({
				url:uni.getStorageSync("localurl")+'/Common/GetAPPUserModel',
				data: {
				},
				success: (res) => {
					//console.log(res);
					self.UserId=res.data.UserId;
					self.DepartmentId=res.data.DepartmentId;
				},
				fail: () => {
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
			})
			 var data = {
			            "_r": "661aea12-cb28-4c92-9a78-66c519a630c9",
			            "act": options.act
			        }
			        //使用ID换code
			        if (options.document_id) {
			            data.DocumentId = options.document_id;
						self.DocumentId=options.document_id;
			        }
			//底部导航结束
			//Get_Document_Model
			uni.request({
				url:uni.getStorageSync("localurl")+'/Documents/Get_Document_Model',
				data: data,
				success: (res) => {
					console.log(res);
					if (res.data.successed == true) {
						console.log(res.data.model.可以添加明细);
						 self.Addflag=res.data.model.可以添加明细;
						 self.inputzdr=res.data.model.制单人;
						  self.inputzdbm=res.data.model.制单部门;
						  if(res.data.model.处理方式!=null){
							self.inputclfs=res.data.model.处理方式;
							}
						  self.inputzdrq=res.data.model.制单日期;
						  self.inputdjbh=res.data.model.单据编号;
						  if(res.data.model.处理方式=="直接出库"){
							self.inputzdbmspan="使用部门";
							 self.inputzdrspan="使用人";
							}
						if(res.data.model.处理方式=="借用出库"){
													self.inputzdbmspan="借用部门";
													 self.inputzdrspan="借用人";
													 
													}
						if(res.data.model.处理方式=="领用出库"){
													self.inputzdbmspan="领用部门";
													 self.inputzdrspan="领用人";
													}
						
							  
						}
					},
					fail: () => {
							//  请求失败,隐藏加载状态
							this.mescroll.endErr()
						}
					})

			//this.queryasset();
		
		
		}
	}
</script>

<style>
	.item-icon-bt{
		width: 30upx;
		height: 30upx;
	}
	.item-icon-sys {
		width: 40upx;
		height: 40upx;
	}
.scroll-view_H{
		background-color: #edf1f4;
		padding-left: 10px;
		padding-right: 10px;
		overflow: hidden;
	}
	.Item {
		border: 1px solid #e6e6e6;
		overflow: hidden;
		padding-bottom: 16rpx;
		border-radius: 16rpx;
		background: #fff;
		margin-top: 10rpx;
	}
	
	.item-text .span {
		display: inline-block;
		width: 67%;
		float: right;
	}
	
	.item-text .ispan {
		font-style: normal;
		width: 30%;
		display: inline-block;
	}
	
	.item-content {
		padding-left: 0;
	}
	
	.item-title .ispan {
		font-size: 30rpx;
		width: auto;
		height: auto;
	}
	
	.item-title {
		font-size: 40rpx;
		color: #454545;
		width: 100%;
	}
	
	.item-title-row {
		background-image: none;
		padding-right: 0px;
	}
	
	.item-link .item-inner {
		padding-right: 0;
	}
	.item-text {
		font-size: 30rpx;
		color: #454545;
		margin: 20rpx 0;
		padding-left: 20rpx;
		line-height: 1.2;
	}
	
	.box{
		width: 700rpx;border-bottom: 1px #f0f0f0 solid;
		height: 80rpx;
		line-height: 80rpx;
	}
	.box .popupspan{
		width: 36.5%;display: inline-block;height: 80rpx;
		line-height: 80rpx;
		padding-left: 3.5%;
		color: #5a5a5a;
	}
	.box .popupinput{
		width: 52%;text-align: right;display: inline-block;height: 80rpx;line-height: 80rpx;
		padding-right: 30rpx;
		float: right;
	}
	.box .popupinput input{	
		height: 100%;line-height: 100%;
		font-size: 30rpx;
	}
	.inputff{
			color: #BEBEBE;
			font-size:30rpx;
		}
		.box .popupinput{
			font-size:30rpx;
			}
			
			
			
			
			.ispancheck{
				transform:scale(0.7);
				border-color: "#32cacb";
			}
			.ispancheck:hover{
				transform:scale(0.7);
				border-color: "#32cacb";
			}
</style>
